<?php

class round extends Model {
	private $_TotalMatches;
	private $_Matches;

	private function _setDefaultValues($arrInitialValues = null){
		if (isset($arrInitialValues['total_matches']) && !empty($arrInitialValues['total_matches']))
			$this->setTotalMatches($arrInitialValues['total_matches']);
		else 
			$this->setTotalMatches(0);
	}

	public function __construct($arrInitialValues = null){
		$this->setTable('rounds');
		$this->setColumnId('round_id');

		$this->_setDefaultValues($arrInitialValues);
		parent::__construct($arrInitialValues);
		$this->setActive(1);
	}

	public function getTotalMatches(){
		return $this->_TotalMatches;
	}

	public function setTotalMatches($value){
		$this->_TotalMatches = $value;
	}

	public function getMatches(){
		return $this->_Matches;
	}

	public function setMatches($value){
		$this->_Matches = $value;
	}
	
	public function getAllMatches($tournament_id){
		$query = '
			SELECT *
			FROM matches
			WHERE tournament_id = ' . $tournament_id . '
				AND round_id = ' . $this->getId();

		$dbHelper = new DBHelper($query);
		return $dbHelper->getResult();
	}
	
	public function getAllSeries($tournament_id){
		$query = '
			SELECT * 
			FROM serie
			WHERE round_id = ' . $this->getId() . '
				AND tournament_id = ' . $tournament_id;

		$dbHelper = new DBHelper($query);
		return $dbHelper->getResult();
	}

}

?>